<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">


    <title> 留言列表</title>
    <meta content="" name="keywords">
    <meta content="" name="description">

    <link href="favicon.ico" rel="shortcut icon">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <!--<link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">-->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert2.css?v4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <!--<link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="/static/hAdmin/css/style3.css?v4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <style>
        .addList {
            padding: 10px 30px 10px 30px;
            height: 90px;
            margin-top: 3px
        }
    </style>

</head>

<body class="gray-bg animated bounceInDown">
<div id="block"
     style="width: 100%;height: 100%;background: #171717;opacity: 0.7;position: fixed;top: 0;left: 0;z-index: 999;text-align: center;display: none">
    <div style="margin-top: 300px">
        <span style="color: #ffffff;font-size: 20px;font-weight: 700">正在提交本次操作，请勿进行任何操作......</span>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInUp">
    <span id="gloUrl" style="display: none"></span>

    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title" style="height: 55px;">
                    <h5>所有记录</h5>
                    <div class="ibox-tools">
                        <div class="text-center">
<!--                            <button type="button" class="btn btn-primary schoolUnDo" data-toggle="modal" data-target="#myModal">-->
<!--                                留言-->
<!--                            </button>-->
                        </div>

                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-1">
                            <button class="btn btn-white btn-sm" id="loading-example-btn" type="button"><i
                                    class="fa fa-refresh"></i>
                                刷新
                            </button>
                        </div>
                        <div class="col-md-11 form-inline">
<!--                            <div class="input-group col-xs-5">-->
<!--                                <input class="input-sm form-control" id="searchKey" placeholder="请根据 企业名 或 企业负责人 进行关键词匹配"-->
<!--                                       type="text">-->
<!--                            </div>-->

<!--                            <div class="input-group">-->
<!--                                <button class="btn btn-sm btn-primary" id="getByKeywords"-->
<!--                                        type="button">搜索-->
<!--                                </button>-->
<!--                            </div>-->
                        </div>
                    </div>
                    <!--            列表          -->
                    <div class="project-list">
                        <table class="table table-hover">
                            <tbody id="listBody"></tbody>
                        </table>
                    </div>
                    <!--                        页码控制-->
                    <div ajaxUrl="www.baidu.com" currentPage="1" id="pageHelper">
                        <div class="pageBottom col-xs-10 col-xs-offset-1" style="margin-top: 20px">
                            <nav aria-label="...">
                                <ul class="pager">
                                    <li class="previous disabled"><a href="javascript:void(0)"><span aria-hidden="true">&larr;</span>
                                        Older</a></li>
                                    <li>
                                        <span>共</span>
                                        <span id="data_total">${total}</span>
                                        <span>条数据</span>
                                    </li>
                                    <li class="next"><a href="javascript:void(0)">Newer <span
                                            aria-hidden="true">&rarr;</span></a></li>
                                </ul>
                            </nav>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<div class="modal inmodal" id="myModalMessage"  tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" >
        <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <i class="fa fa-pencil modal-icon" style="font-size: 60px"></i>
                <h4 class="modal-title">留言</h4>

            </div>
            <div class="formListAdd">

                <div class="modal-body addList" style="height: 200px;">
                    <div class="form-group">
                        <div class="col-xs-12">
                            <label>内容</label>
                        </div>

                        <div class="col-xs-12">
                            <textarea type="text" placeholder="输入内容" rows="5" id="message"  class="form-control"></textarea>
                        </div>

                    </div>
                </div>

                <div class="modal-footer">

                    <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmSend">发送
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>

<!-- 自定义js -->
<script src="/static/hAdmin/js/content.js?v=1.0.0"></script>
<!--    分页js -->
<!--<script src="/static/wmmJs/public/PageHelper.js"></script>-->
<script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/static/js/GloJs.js"></script>
<script>


    $(function () {

        let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
        let Glo_user = localStorage.getItem("userId")
        let currentPage = $("#pageHelper").attr("currentPage");

        getRoleSetMenu()
        //获取消息列表
        function getMessageList(){
            let total = 0;//总数
            let pageSize = 6;//每页条数
            let html_dom = $("#listBody")
            $.ajax({
                url: Glo_BaseUrl + "/message/list",
                type: "get",
                data:{
                    "pageSize": 6,
                    "pageNum": currentPage,
                    "receiveId":Glo_user,
                },
                success: function (data) {
                    let ListStr = ''
                    let specialBtn = ``

                    for (let i = 0; i < data.list.length; i++) {
                        let typeStr = `   <td class="project-completion">
                                                <small>留言方：<span id="dataForClass">${data.list[i].senderName}</span> </small>

                </td>`
                        let item = data.list[i]
                        if (item.type === null){
                            typeStr = ``
                        }
                        let statusStr = `<td class="project-status">
                                        <span class="label label-default" >已回复</span>
                                        </td>`
                        specialBtn = `

                                <button class="btn btn-sm btn-danger stopBtn" thisId="${item.id}" title="删除"> <i class="fa fa-close"></i> </button>
                                `
                        if (item.status === '0'){
                            statusStr = `<td class="project-status">
                                        <span class="label label-danger" >未回复</span>
                                        </td>`
                            specialBtn = `
<button class="btn btn-warning btn-sm seeRentDetail" title="查看" id="seeRentDetail" data-toggle="modal" data-target="#myModalMessage"
                 thisId="${data.list[i].id}" senderId="${data.list[i].senderId}"><i class="fa fa-edit"></i>  </button>
                                <button class="btn btn-sm btn-danger stopBtn" thisId="${item.id}" title="删除"> <i class="fa fa-close"></i> </button>
                                `
                        }


                        ListStr +=
                            `<tr>`+statusStr+`
                                        <td class="project-title">
                                            <span > <strong> ${data.list[i].content}</strong> </span>
                                            <br/>
                                              <small>接收方：<span id="EventTime">${data.list[i].receiveName}</span> </small>
                                        </td>


             `+typeStr+`
    <td class="project-completion">
                                                <small>发送时间：<span id="dataForClass">${data.list[i].createTime}</span> </small>

                </td>
                <td class="project-actions">

` + specialBtn + `

                                 </td>
                </tr>
                `

                    }

                    if (data.code !== 500) {
                        html_dom.html("")
                        html_dom.append(ListStr)
                    } else {
                        alert("获取失败")
                    }
                    total = data.total
                    $("#data_total").html(data.total);
                    //下一页
                    $('.next').unbind().click(function () {
                        if (currentPage * pageSize >= total) {
                            toastr.error("已经是最后一页了！", '提醒')
                        } else {
                            currentPage++;
                            $("#pageHelper").attr("currentPage", currentPage);
                            if (currentPage > 0) {
                                $(".previous").removeClass("disabled")
                            }
                            $(".project-list").addClass("animated bounceOutLeft")
                            setTimeout(function () {
                                $(".project-list").removeClass("animated bounceOutLeft").addClass("animated bounceInRight")
                            }, 500)
                            getMessageList(2)
                        }

                    });
                    //上一页
                    $('.previous').unbind().click(function () {
                        currentPage--;
                        $("#pageHelper").attr("currentPage", currentPage);
                        if (currentPage === 0) {
                            currentPage = 1;
                            $("#pageHelper").attr("currentPage", currentPage);
                            $(".previous").addClass("disabled");
                        } else {
                            $(".project-list").addClass("animated bounceOutRight")
                            setTimeout(function () {
                                $(".project-list").removeClass("animated bounceOutRight bounceInRight").addClass("animated bounceInLeft")
                            }, 500)
                            getMessageList(2)
                        }
                    });
                    $(".seeRentDetail").click(function (){
                        localStorage.setItem("id",$(this).attr("thisId"))
                        localStorage.setItem("senderId",$(this).attr("senderId"))
                    })
                    //发送
                    $("#confirmSend").click(function (){


                        var formData = new FormData();//这里需要实例化一个FormData来进行文件上传

                        formData.append("senderId",Glo_user);
                        formData.append("receiveId",localStorage.getItem("senderId"));

                        formData.append("content",$("#message").val());
                        formData.append("id",localStorage.getItem("id"));



                        // console.log(f)
                        $.ajax({
                            url: Glo_BaseUrl + "/message/add",
                            type: "post",
                            data:formData
                            ,
                            processData : false,
                            contentType : false,
                            success: function (data) {
                                console.log(data)
                                if (data.code === 200) {
                                    toastr.success("成功", '提示!')
                                    $("#close").click()
                                } else {
                                    toastr.error(data.msg, '提示!')
                                }
                                getMessageList();

                            },
                            error: function () {
                                alert("服务器异常！network error！")
                            }
                        })
                    })



                    //停用
                    $(".stopBtn").unbind("click").click(function () {
                        let id = $(this).attr("thisId")
                        swal({
                            title: "您确定要删除此消息？",
                            text: "删除不可恢复！",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "删除",
                            cancelButtonText: "取消",
                            closeOnConfirm: false
                        }, function () {
                            $.ajax({
                                url: Glo_BaseUrl + "/message/del",
                                type: "post",
                                data: {
                                    "id": id,

                                },
                                success: function (data) {
                                    if (data.code === 200) {
                                        swal("删除成功！", "您已经删除了此消息。", "success");
                                        getMessageList()
                                    } else {
                                        swal("删除失败！", "删除失败。", "error");
                                    }

                                },
                                error: function () {
                                    alert("服务器异常！network error！")
                                }
                            })
                        });
                    });
                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        }

        getMessageList()
        $("#confirmAddEq").click(function () {

            var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
            formData.append("senderId",Glo_user);
            formData.append("receiveId",1);
            formData.append("content",$("#content").val());
            formData.append("status","1");
            formData.append("type",role);
            $.ajax({
                url: Glo_BaseUrl + "/message/add",
                type: "post",
                data:formData
                ,
                processData : false,
                contentType : false,
                success: function (data) {

                    if (data.code === 200) {
                        toastr.success("成功", '提示!')
                        $("#close").click()
                    } else {
                        toastr.error(data.msg, '提示!')
                    }
                    getMessageList();

                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })
    })
</script>
</body>
</html>
